﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;

namespace EIA.SLClient.ProjectManage.Basic
{
    public class QueryBoxViewModel : SimpleMvvmToolkit.ViewModelBase<QueryBoxViewModel>
    {
        public QueryBoxViewModel()
        {

        }
        #region notifyprop

        protected string _Keyword;
        /// <summary>
        /// 注释
        /// </summary>
        public string Keyword
        {
            get { return _Keyword; }
            set
            {
                _Keyword = value;
                NotifyPropertyChanged(m => m.Keyword);
            }
        }

        protected Dictionary<string,object> _PlusConditions;
        /// <summary>
        /// 注释
        /// </summary>
        public Dictionary<string,object> PlusConditions
        {
            get { return _PlusConditions; }
            set
            {
                _PlusConditions = value;
                NotifyPropertyChanged(m => m.PlusConditions);
            }
        }


        #endregion

        #region QueryCommand

        private SimpleMvvmToolkit.DelegateCommand _QueryCommand = null;
        public SimpleMvvmToolkit.DelegateCommand QueryCommand
        {
            get
            {
                if (_QueryCommand == null)
                {
                    _QueryCommand = new SimpleMvvmToolkit.DelegateCommand(Query, CanExcuteQuery);
                } return _QueryCommand;
            }
            set { _QueryCommand = value; NotifyPropertyChanged(m => m.QueryCommand); }
        }

        public void Query()
        {
            string queryTitle = "关键字：" + Keyword;
            Dictionary<string, object> con = new Dictionary<string, object>();
            if (PlusConditions != null)
            {
                foreach (var k in PlusConditions.Keys)
                {
                    con[k] = PlusConditions[k];
                }
            }
            con[EIA.PM.Model.TProjectBasic.PRJ_NAME] = Keyword == null ? "" : Keyword;
            SendMessage(EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.PROJECT_QUERY, new SimpleMvvmToolkit.NotificationEventArgs<Dictionary<string, object>>(queryTitle, con));
        }

        public bool CanExcuteQuery()
        {
            return true;
        }

        #endregion

    }
}